﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DeviceInfoManage.BusinessLogicLayer;
using System.Text;

public partial class FileView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /*对进行查询的设备类型下拉框各项进行设置*/
        if (!IsPostBack)
        {
            if (Session["adminUserName"] == null)
            {
                Response.Redirect("logout.aspx");
            }

            DataSet ds = (new FileType()).GetFileType();
            ddlfileType.DataSource = ds;
            ddlfileType.DataTextField = "fileTypeName";
            ddlfileType.DataValueField = "fileTypeId";
            ddlfileType.DataBind();
            ddlfileType.Items.Insert(0, new ListItem("请选择", ""));

            ds = (new MaintPerson()).GetMaintPersonName();
            ddluploadUser.DataSource = ds;
            ddluploadUser.DataTextField = "maintPersonName";
            ddluploadUser.DataValueField = "maintPersonName";
            ddluploadUser.DataBind();
            ddluploadUser.Items.Insert(0, new ListItem("请选择", ""));
        }

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标选择某行时变颜色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00ffee';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            //e.Row.Cells[6].Text = Convert.ToDateTime(e.Row.Cells[6].Text).ToShortDateString();
        }
    }

    protected void Btn_Query_Click(object sender, EventArgs e)
    {
        StringBuilder strSql = new StringBuilder();
        if (!string.IsNullOrEmpty(txtfileName.Text)) { strSql.Append(" fileName like '%" + txtfileName.Text + "%'"); }
        if (ddlfileType.SelectedValue != "") { strSql.Append(" AND fileType = '" + ddlfileType.SelectedItem.Text + "'"); }
        if (ddluploadUser.SelectedValue != "") { strSql.Append(" AND uploadUser = '" + ddluploadUser.SelectedItem.Text + "'"); }
        if (strSql.ToString().StartsWith(" AND")) { strSql = strSql.Remove(0, 4); }
        this.GridView1.DataSourceID = null;
        this.GridView1.DataSource = (new FileManage()).GetList(strSql.ToString());
        this.GridView1.DataBind();

    }

    protected void lkbDel_Click(object sender, EventArgs e)
    {
        LinkButton lkb = sender as LinkButton;
        if (lkb.CommandArgument.Split(':')[0] == Session["adminUserName"].ToString() || Session["adminType"].ToString() == "管理员")
        {
            (new FileManage()).Delete(int.Parse(lkb.CommandArgument.Split(':')[1]));
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('操作成功!');window.location=\"" + Request.Url.ToString() + "\"</script>");
        }
        else
        {
            //Response.Write("<script>alert('没有权限删除此文件');</script>");
            Response.Write("<script>alert('" + lkb.CommandArgument.Split(':')[0] + "');</script>");
        }
    }
}
